 /*
 * @description: 客服管理/掌大客服
 * @Author: along
 * @Date: 2020-09-27
 * @Last Modified by: along
 * @Last Modified time: 2020-09-27
 */
<template>
    <div class="customZd">
        <!-- filter -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <p class="header-new-box-title">账号状态</p>
                    <el-select
                        v-model="formData.account"
                        clearable
                        filterable
                        placeholder="请选择状态"
                        size="small"
                        @change="getTableData()"
                    >
                        <el-option
                            v-for="item in formData.accountList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
            </div>
        </div>

        <!-- 掌大客服 -->
        <el-table
            :data="tableData"
            style="width: 100%;"
            height="100%"
            border
        >
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                prop="nickname"
                label="员工姓名"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="phone"
                label="联系方式"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="create_time"
                label="绑定时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                label="工作时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    <p
                        @click="fnCheckWordDate(scope.row)"
                        class="cursor-font"
                    >查看</p>
                </template>
            </el-table-column>
            <el-table-column
                prop="status"
                label="状态"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    <p
                        v-if="scope.row.status == 1"
                    ><span class="enable" />已启用</p>
                    <p
                        v-else-if="scope.row.status == 0"
                        :style="{color: '#999999'}"
                    ><span class="out_service" />已停用</p>
                    <p v-else>--</p>
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
            >
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        class="curse-add"
                        v-if="scope.row.status == 1"
                        @click="fnModify(scope.row)"
                    >
                        停用
                    </el-button>
                    <el-button
                        type="text"
                        class="curse-add"
                        v-if="scope.row.status == 0"
                        @click="fnModify(scope.row)"
                    >
                        启用
                    </el-button>
                    <el-button
                        type="text"
                        class="curse-add"
                        @click="fnSetWorkDate(scope.row, scope.$index)"
                    >
                        设置
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页 -->
        <div class="pagination-wrapper clearfix">
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>

        <!-- 查看排期时间 -->
        <el-dialog
            title="排期时间"
            :visible.sync="dialogVisible"
            :close-on-click-modal="false"
            width="510px"
        >
            <el-table
                :data="dateList"
                style="width: 100%;max-height:450px"
                height="100%"
                :show-header="false"
                border
            >
                <el-table-column
                    type="index"
                    width="80"
                    label="序号"
                    align="center"
                />
                <el-table-column
                    prop="start_time"
                    label="排期时间"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                >
                    <template slot-scope="scope">
                        {{ scope.row.start_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }} ~ {{ scope.row.end_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>
    </div>
</template>

<script>

const LIST = {
    account: 99,//掌大客服账号状态
    accountList: [{value: 99, label: '全部'},{value: 0, label: '已停用'},{value: 1, label: '已启用'}],//掌大客服账号状态列表
};

export default {
    name: 'CustomZd',
    data () {
        return {
            dateList: [],
            formData: {
                ...LIST
            },
            //掌大客服
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            tableData: [],
            authResult: {},
            dialogVisible: false
        };
    },
    mounted () {
        this.init();
    },
    methods: {
        /**
         * @description 页面数据初始化
         */
        init () {
            this.$store.commit('SET_HEADER', [{ title: "APP后台"},{ title: "客服系统"},{title: '客服管理'},{title: '掌大客服'}]);
            this.authResult = this.$route.meta.authResult;
            this.getTableData(1);
        },

        /**
         * @description 获取掌大客服数据列表
         */
        getTableData (page) {
            this.$post('/student/customer_service_zsdx%5Cget_list', {
                page_id: page || this.page.now_page,
                status: this.formData.account
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });
        },

        /**
         * @description 查看掌大客服排期时间
         */
        fnCheckWordDate (row) {
            const start_time = this.getDate(0) / 1000;
            const end_time = this.getYear() / 1000;

            this.$post('/student/customer_service_zsdx%5Cget_schedule',{
                kf_no: row.kf_no,
                start_time: start_time,
                end_time: end_time
            },resp=>{
                if (resp.code == 1) {
                    this.dateList = resp.data.list;
                    this.dialogVisible = !this.dialogVisible;
                } else if (resp.code == 0) {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        type: 'warning',
                        duration: 2000
                    });
                }
            });
        },

        /**
         * @description 获取指定日期时间戳
         */
        getDate (day) {
            let tempDate = new Date();
            let retult_milliseconds = tempDate.getTime() + 1000 * 60 * 60 * 24 * day;

            tempDate.setTime(retult_milliseconds);

            let result_Year = tempDate.getFullYear(),
                result_Month = (tempDate.getMonth() + 1).toString(),
                result_Date = tempDate.getDate().toString();

            if (result_Month.length === 1) {
                result_Month = "0" + result_Month;
            }

            if (result_Date.length === 1) {
                result_Date = "0" + result_Date;
            }

            let date = result_Year + "-" + result_Month + "-" + result_Date + " " + "00:00:00";

            return new Date(date).getTime();
        },

        /**
         * @description 获取一年后当天的时间戳
         */
        getYear () {
            let year = new Date().getFullYear() + 1;
            let month = new Date().getMonth() + 1;
            let date = new Date().getDate();

            month = month < 10 ? 0 + month : month;
            date = date < 10 ? 0 + date : date;

            return new Date(year+'-'+month +'-'+date + ' ' + '00:00:00').getTime();
        },

        /**
         * @description 启用停用掌大客服
         */
        fnModify (row) {
            const notice = row.status == 1 ? '是否停用该客服？' : '是否启用该客服';

            this.$confirm(notice, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/student/customer_service_zsdx%5Cset_status',{
                    kf_no: row.kf_no,
                    status: row.status == 1 ? 0 : 1
                },resp=>{
                    if (resp.code == 1) {
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            message: '操作成功',
                            type: 'success',
                            duration: 2000
                        });
                    } else if (resp.code == 0) {
                        this.$notify({
                            title: '提示',
                            message: resp.msg,
                            type: 'warning',
                            duration: 2000
                        });
                    }
                });
            });
        },

        /**
         * @description 掌大客服设置
         */
        fnSetWorkDate (row, index) {
            this.$router.push({
                name: 'customSetting',
                query: {
                    no: JSON.stringify(
                        {
                            ...row,
                            index: index
                        }
                    )
                }
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
.customZd {
    width: 100%;
    height: 100%;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    position: relative;
    .wrap-title {
        color: #333333;
        font-weight: 500;
        font-size: 16px;
        display: flex;
        cursor: pointer;
        margin-bottom: 20px;
        .el-icon-hand-bangzhu {
            font-size: 15px;
            color: #666666;
            margin-left: 8px;
        }
    }
    .header-nav {
        position: relative;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        margin-top: 9px;
        .header-left, .header-right {
            display: flex;
            align-items: center;
            flex-wrap: wrap;
        }
        .header-new-box {
            display: flex;
            margin-right: 15px;
            align-items: center;
            color: #333333;
            margin-bottom: 10px;
            white-space: nowrap;
            &-title {
                margin-right: 16px;
                white-space: nowrap;
            }
        }
    }
    .cursor-font {
        color: #20A0FF;
        cursor: pointer;
    }
    .enable,.out_service {
        display: inline-block;
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: #4CD964;
        margin-right: 6px;
        position: relative;
        top: -2px;
    }
    .out_service {
        background: #FF3030;
    }
    /* 分页 */
    .pagination-wrapper {
        padding-top: 10px;
        padding-bottom: 10px;
        .el-pagination {
            float: right;
            padding: 0;
            background-color: transparent;
        }
    }
    .table-button {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
}
</style>

<style lang="less">
.customManagement {
    .el-tabs__nav {
        .el-tabs__item {
            color: #999999;
        }
        .is-active {
            font-weight: 500;
            color: #20A0FF;
        }
    }
    .el-tabs__nav-wrap::after {
        background-color: #EBEEF5;
    }
    .el-table__body-wrapper .el-table__body .el-table__row td {
        border-right: none;
    }
    .el-table__header-wrapper .el-table__header .has-gutter tr th {
        border-right: none;
    }
    .el-table .el-table_1_column_6  .cell {
        position: relative;
    }
    .el-range-editor--small .el-range-separator{
        padding: 0 1px !important;
    }
    .table-button .el-button {
        padding: 4px 0;
        margin-left: 0;
    }
    .el-dialog__header {
        padding-top: 10px;
        box-shadow:0px 1px 0px 0px rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    .el-dialog__body {
        padding: 30px 20px !important;
    }
    .el-table__body-wrapper {
        &::-webkit-scrollbar {
            width: 4px;
            border-radius: 3px;
        }
    }
}
.reception-poper {
    color: #666666;
    line-height: 20px;
    font-size: 13px;
    padding: 16px;
}
</style>